package com.ruoyi;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * ali 发送短信
 */
public class AliSmsUtils {

    private static AliSmsModel aliSmsModel;

    public static void setAliSmsModel(AliSmsModel aliSmsModel) {
        AliSmsUtils.aliSmsModel = aliSmsModel;
    }
//    public static CommonResponse sendSms(String templateKey,String phone,String json ){
//        sendSms(aliSmsModel.getSignName(),)
//    }
    private static CommonResponse sendSms(String signName, String templateCode, String paramString, String phoneNumber) throws ClientException {
        DefaultProfile profile = DefaultProfile.getProfile(aliSmsModel.getRegionId(), aliSmsModel.getAccessKeyId(), aliSmsModel.getAccessSecret());
        IAcsClient client = new DefaultAcsClient(profile);
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", aliSmsModel.getRegionId());
        request.putQueryParameter("PhoneNumbers", phoneNumber);
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
        request.putQueryParameter("TemplateParam", paramString);
        return client.getCommonResponse(request);
    }


}
